﻿using SUNRPA.CONTROLS.IMPL.domain.attrubutes;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;
using System.IO;

namespace SUNRPA.CONTROLS.IMPL.domain.flowItemParam {
    [Serializable]
    [VarFieldName("FileSavePathOutVar")]
    public class DealDownLoadDialogNParam : BaseParam {
        //google 0，IE 1， edge 2
        private BrowserType browType = BrowserType.GOOGLE;
        //0确定，1取消
        private int buttonType = 0;
        //等待下载对话框超时时间
        private string waitDialogTime = "20";
        //保存文件夹路径
        private string savePath =  Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+Path.DirectorySeparatorChar+"Downloads";
        private bool renameDownloadFile = false;
        private bool waitingDownloadFinish = true;
        //重命名名称
        private string saveFileName;
        //下载超时时间
        private string expireTime = "300";
        //下载地址输出变量
        private string fileSavePathOutVar = "fileSavePath";

        public int ButtonType {
            get => buttonType; 
            set { 
                buttonType = value;
                NotifyPropertyChanged("ButtonType");
            }  
        }

        public BrowserType BrowType {
            get => browType; 
            set { 
                browType = value;
                NotifyPropertyChanged("BrowType");
            }  
        }

        public string FileSavePathOutVar {
            get => fileSavePathOutVar; 
            set { 
                fileSavePathOutVar = value;
                NotifyPropertyChanged("FileSavePathOutVar");
            }  
        }

        public string ExpireTime {
            get => expireTime; 
            set { 
                expireTime = value;
                NotifyPropertyChanged("ExpireTime");
            }  
        }

        public bool WaitingDownloadFinish {
            get => waitingDownloadFinish; 
            set { 
                waitingDownloadFinish = value;
                NotifyPropertyChanged("WaitingDownloadFinish");
            }  
        }

        public string SaveFileName {
            get => saveFileName; 
            set { 
                saveFileName = value;
                NotifyPropertyChanged("SaveFileName");
            }  
        }

        public bool RenameDownloadFile {
            get => renameDownloadFile; 
            set { 
                renameDownloadFile = value;
                NotifyPropertyChanged("RenameDownloadFile");
            }  
        }

        public string SavePath {
            get => savePath; 
            set { 
                savePath = value;
                NotifyPropertyChanged("SavePath");
            }  
        }
        public string GetTranslateWaitingDownloadFinish() {
            if(true) { 
                return $"最多等待{this.expireTime}后，";
            } else { 
                return "";
            }
        }

        public string GetTranslateBrowType() {
            switch(this.browType) {
                case BrowserType.GOOGLE:
                    return "GOOGLE";
                    break;
                case BrowserType.IE:
                    return "IE";
                    break;
                case BrowserType.EDGE:
                    return "EDGE";
                    break;
                default:
                    return "GOOGLE";
                    break;
            }
        }
        
        public string GetTranslateButtonType() {
            switch(this.buttonType) {
                case 0:
                    return $"确定按钮，文件下载至{this.savePath}，下载路径保存至{this.FileSavePathOutVar}";
                    break;
                case 1:
                    return "取消按钮";
                    break;
                default:
                    return "取消按钮";
                    break;
            }
        }

        public string GetTranslateRenameDownloadFile() {
            if(true) { 
                return $"重命名为{this.saveFileName}";
            } else { 
                return "";
            }
        }

        public string WaitDialogTime {
            get => waitDialogTime; 
            set { 
                waitDialogTime = value;
                NotifyPropertyChanged("WaitDialogTime");
            }  
        }
        public override void SetLatestVarName(ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData) {
            this.fileSavePathOutVar = this.GetLatestName(this.fileSavePathOutVar, globleData);
        }
    }
}
